﻿<?php
    session_start();
    include('database.php');

    $_SESSION['curPage'] = 'home.php';  
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Diablo 3 Lottery</title>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <div class="d_body">

            <?php include('header.php'); ?>
            <?php include("language.php"); ?>
            <?php include("menuBar.php"); ?>         
            
            <section>
            <?php
                if(isset($_SESSION['connected']) AND $_SESSION['connected'])
                {
                    if(isset($_GET['draw_id']))
                    {
                        $lquery = $db->prepare("SELECT * FROM drawparticipation WHERE draw_id = ? AND user_id = ? ORDER BY ticket_id DESC");
                        $lquery->execute(array($_GET['draw_id'], $_SESSION['id']));
                        
                        $lquery2 = $db->prepare("SELECT date from draw WHERE id = ?");
                        $lquery2->execute(array($_GET['draw_id']));
                        
                        $data2 = $lquery2->fetch();
                        
                        echo '<h1>' . $drawParticipation_yourParticipation . date("d/m/Y ", strtotime($data2['date'])) . '</h1>';
                        
                        if($lquery->rowCount() > 0)
                        {                            
                            echo '<p>'. $drawParticipation_youUsed . $lquery->rowCount() . $drawParticipation_youUsed2 . '</p>';
                            echo '<table class="drawTable">';
                            echo    '<tr>';
                            echo        '<th>Ticket</th>';
                            echo        '<th>' . $draws_dateOfUse . '</th>';
                            echo        '<th>' . $drawParticipation_winnerTicket . '</th>';
                            echo    '</tr>';
                            
                            while($data = $lquery->fetch())
                            {
                                echo '<tr>';
                                echo '<td class="cellTextCenter">#' . $data['ticket_id'] . '</td>';
                                echo '<td class="cellTextCenter">' . date("d/m/Y " . $draws_at . " H:i \G\M\T+1", strtotime($data['participationDate'])) . '</td>';
                                if($data['winnerTicket']) echo '<td class="cellTextCenter" class="green"><strong>' . $drawParticipation_yes . '<strong></td>';
                                else echo '<td class="cellTextCenter">' . $drawParticipation_no . '</td>';
                                echo '</tr>';
                            }
                            echo '</table>';
                        }
                        else 
                        {
                            echo '<p>' . $drawParticipation_youBoughtNoTickets . '</p>';
                        }
                    }
                }
                else 
                {
                    echo '<p class="text_error">' . $drawParticipation_youMustBeConnected . '</p>';
                }
            ?>            
            </section>
        </div>
        <?php include('footer.php'); ?>
    </body>
</html>